
#pragma once

#include "olisp_cfg.h"

#include <stddef.h>

#if defined(_DEBUG) && defined(_MSC_VER)
#define OLISP_DBG_MEM_IMPL

#include <crtdbg.h>
#include <string.h>

#define lisp_malloc(s)      _malloc_dbg(s, _NORMAL_BLOCK, __FILE__, __LINE__)
#define lisp_realloc(p, s)  _realloc_dbg(p, s, _NORMAL_BLOCK, __FILE__, __LINE__)
#define lisp_free(p)        _free_dbg(p, _NORMAL_BLOCK)

void * lisp_mallocz_impl( size_t s, const char * file, int line );
char * lisp_strdup_impl( const char * s, const char * file, int line );

#define lisp_mallocz(s) lisp_mallocz_impl(s, __FILE__, __LINE__)
#define lisp_strdup(s) lisp_strdup_impl(s, __FILE__, __LINE__)

void lisp_dump_mem_leaks();

#else

void * lisp_malloc( size_t s );

void lisp_free( void * p );

void * lisp_realloc( void * p, size_t s );

void * lisp_mallocz( size_t s );

char * lisp_strdup( const char * s );

STATIC_INLINE void lisp_dump_mem_leaks()
{}

#endif
